package com.animations;

import com.beans.BirdBean;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.bean.Switch;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.util.ArrayList;

public class PlayFlyAction2 extends Animation {

  private BirdBean birds;
  private ArrayList<Image> bird;
  private int birdSub = 1;

  public void loadBean() {
    this.birds = new BirdBean();
    getBeans().add(this.birds);
  }

  public void paint(Graphics g) {
    if (this.bird == null) this.bird = this.birds.getBird();
    Graphics2D g2d = (Graphics2D) g;
    if (!BirdFlyAction.hiddenBird) {
      g2d.rotate(
        Math.toRadians(BirdBean.getR()),
        BirdBean.getBirdGameX() + BirdBean.getBirdW() / 2,
        BirdBean.getBirdY() + BirdBean.getBirdH() / 2
      );
      g2d.drawImage(
        (Image) this.bird.get(this.birdSub),
        BirdBean.getBirdGameX(),
        BirdBean.getBirdY(),
        getMagicanvas()
      );
    }
  }

  public synchronized void run() {
    boolean birdrisAble = true;
    while ((Switch._isContinue()) && (BirdBean._isAlive())) {
      if (birdrisAble) this.birdSub += 1; else this.birdSub -= 1;
      if (this.birdSub == 0) birdrisAble = true;
      if (this.birdSub == 2) birdrisAble = false;
      try {
        if (Tag._isPlay()) Thread.sleep(90L); else Thread.sleep(110L);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      getMagicanvas().repaint();
    }
    this.birdSub = 1;
    getMagicanvas().repaint();
  }
}
